package edu.sctu.zhoumengxue.day201506.day20150625.practiceURL;

import java.io.BufferedReader;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;

/**Java请求一个URL。获取网站返回的数据
 * Created by user12 on 2015/6/25.
 */
public class SentGet {
    public  String SendGet(String url,String param){

        String result="";//访问返回结果
        BufferedReader reader = null;//读取访问结果

        try {
            //创建URL
            URL readurl = new URL(url+"?"+param);
            try {
                //打开连接
                URLConnection connection = readurl.openConnection();

                //设置通用的请求属性
                connection.setRequestProperty("accept","*/*");
                connection.setRequestProperty("connection","keep-Alive");
                connection.setRequestProperty("user-agent","Mozilla/4.0(compatible;MSIE 6.0;Windows NT 5.1;SV1)");

                //建立连接
                connection.connect();
                //获取所有响应头字段


            } catch (IOException e) {
                e.printStackTrace();
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }

return result;
    }
}
